using Microsoft.UI.Xaml.Controls.Primitives;

namespace MultiAgentsClient.Presentation.Component;

public sealed partial class ChatMainArea : UserControl
{
    public ChatMainArea()
    {
        InitializeComponent();
    }

    private void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
    {
        double totalHeight = ChatMainAreaGrid.ActualHeight;
        double row2Height = ChatMainAreaGrid.RowDefinitions[2].ActualHeight;
        double row4Height = ChatMainAreaGrid.RowDefinitions[4].ActualHeight;

        double newRow2Height = row2Height + e.VerticalChange;
        double newRow4Height = row4Height - e.VerticalChange;

        if (newRow2Height > 0 && newRow4Height > 0)
        {
            double row2HeightRatio = newRow2Height / totalHeight;
            double row4HeightRatio = newRow4Height / totalHeight;

            ChatMainAreaGrid.RowDefinitions[2].Height = new GridLength(row2HeightRatio, GridUnitType.Star);
            ChatMainAreaGrid.RowDefinitions[4].Height = new GridLength(row4HeightRatio, GridUnitType.Star);
        }
    }
}
